from common.base_page import BasePage
from time import sleep
from test_datas.string_data import *
from page_locators.login_page_locators import LoginPageLocators as LPL
from test_datas.file_path import *
from test_datas.pic_data import *
from page_objects.user_right_manage_page import UserRightManage as UM
from page_locators.user_manage_page_locators import UserManageLocators as UML
from page_locators.user_right_manage_page_locators import UserRightManageLocators as URML

class UserManage(BasePage):

    def __init__(self,driver):
        super().__init__(driver)
        self.um = UM(driver)

    def click_user_center_app(self):
        self.click(LPL.application, '用户中心应用定位点击')
        sleep(1)

    def switch_user_manage(self):
        self.click_user_center_app()
        self.click(LPL.user_manage, "用户管理菜单定位切换")

    def click_add_user(self):
        self.click(UML.add_user, "添加用户定位点击")

    def add_user(self):
        self.click_add_user()
        self.input(UML.user_name, "testuser1", "用户名定位输入")
        self.input(UML.name, "test_name1", "姓名定位输入")
        self.click(UML.add_user_sure_sub, "添加用户确定按钮定位点击")
        self.click(UML.system_sure, "系统提示确定按钮定位点击")

    def click_enable_user(self):
        sleep(1)
        self.click(UML.enable_sub, "启用按钮定位点击")

    def click_edit(self):
        self.click(UML.edit, "列表第一条数据编辑按钮")
        self.input(UML.name, "name1", "用户名输入")
        self.click(UML.edit_sure, "编辑页面确定按钮点击")
        self.wait(UML.list1_name, 10, 1)

    def add_user2(self):
        self.click_add_user()
        self.input(UML.user_name, "testuser2", "用户名定位输入")
        self.input(UML.name, "test_name2", "姓名定位输入")
        self.click(UML.add_user_sure_sub, "添加用户确定按钮定位点击")
        self.click(UML.system_sure, "系统提示确定按钮定位点击")

    def add_new_user_click_role(self):
        self.add_user2()
        sleep(1)
        self.click(UML.list1_role, '点击test_user2的角色按钮')
        sleep(1)

    def input_face_photo(self):
        self.click(UML.face, "列表第一条数据人脸认证栏点击")
        self.upload_file(UML.input_face, general_path, "上传人脸照片")
        self.get_ele(UML.success_input, "定位上传成功后的img标签")
        self.click(UML.ensure, "取消按钮点击")
        self.wait(UML.face_success, 20, 1)

    def batch_import_users(self):
        self.suspension_loc(UML.handle, UML.batch_import_users, "操作按钮悬浮定位")
        self.upload_file(UML.user_input, input_file2, "上传用户信息文档")
        self.get_ele(UML.success_tips, "文件上传成功提示标签定位")
        self.click(UML.import_sub, "导入按钮点击")
        self.get_ele(UML.result_tips, "导入结果提示标签定位")
        self.click(UML.batch_import_sure, "批量导入确定按钮点击")

    def get_new_users(self):
        user_name1 = self.get_text(UML.name1, "获取导入数据第一条的用户名")
        user_name2 = self.get_text(UML.name2, "获取导入数据第二条的用户名")
        name = f"导入的数据为: {user_name1}, {user_name2}"
        return name

    def click_worktable(self):
        self.click(UML.worktable, "我的工作台点击")
        sleep(1)

    def enter_teachers_info_manage(self):
        self.click_worktable()
        self.click(UML.teacher_info_manage, "教职工信息管理应用点击")
        sleep(1)
        self.click(UML.info_manage_menu, "入职管理菜单点击")

    def perfect_info(self):
        for i in list:
            self.click(i[3], "完善信息点击")
            sleep(1)
            self.input(UML.phone, i[1], "手机号输入")
            sleep(1)
            self.input(UML.id, i[2], "身份证号定位输入")
            sleep(1)
            self.click(UML.pertect_info_sure, '确定按钮点击')
            sleep(1)

    def upload_faces(self):
        self.suspension_loc(UML.handle, UML.batch_import_face, "操作按钮悬浮定位")
        for i in face:
            self.upload_file(UML.batch_input_face, i, "上传人脸照片1")
            sleep(1)
        self.click(UML.batch_input_sure, "确定按钮点击")
        self.wait(UML.system_tip, 25, 1)

    def input_face_photos(self):
        self.enter_teachers_info_manage()
        self.perfect_info()         # 完善身份证号和手机号
        self.click_worktable()      # 点击我的工作台
        self.switch_user_manage()   # 进入用户管理
        self.upload_faces()

    def batch_delete_users(self):
        self.um.click_user_right_manage()   # 用户权限管理定位点击
        self.input(URML.query_sub, "test_user", "搜索框输入")  # 权限管理搜索框输入
        self.um.check_all_user()   # 勾选框全选
        sleep(1)
        self.um.click_batch_assign_roles() # 点击批量分配角色
        self.um.check_and_sure()  # 分配角色
        self.um.batch_deletion_users()  # 批量删除